#!/usr/bin/python
# -*- encoding: UTF-8 -*-

from ftplib import FTP
import time
import os

BACKUP_DIR = "." 
QUEUE_DIR =  ".."
AUTO_DELETE = ["France 5","Arte"]

ftp=FTP("hd1.freebox.fr")
f = file(os.path.join(BACKUP_DIR,".credential"));
cred = f.read().splitlines()[0]
f.close()
splitted = cred.split(',')
ftp.login(splitted[0],splitted[1])
ftp.cwd("Disque dur/Enregistrements")
files = os.listdir(QUEUE_DIR)

for f in files:
    if len(filter(lambda x:f.startswith(x),AUTO_DELETE)) > 0 and f.endswith(".ts"):
        ftp.delete(f)
ftp.quit()
